/**
 * 
 */
package com.istart.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.data.Stat;

/**
 * @author 谢进军
 *
 */
public class ZooKeeperConfig implements Config {

	 @Override
	    public byte[] getConfig(String path) throws Exception {
	        CuratorFramework client = ZooKeeperFactory.get();
	        if (!exists(client, path)) {
	            throw new RuntimeException("Path " + path + " does not exists.");
	        }
	        return client.getData().forPath(path);
	    }
	     
	    private boolean exists(CuratorFramework client, String path) throws Exception {
	        Stat stat = client.checkExists().forPath(path);
	        return !(stat == null);
	    }

}
